from state import State, low, normal
from host import Host
class StateManage():
    def __init__(self):
        self.states = {str:State}
        self.current_state:State = None
        self.value:Host = Host()

    def add_state(self,state_name:str, state:State):
        self.states[state_name] = state

    def set_state(self):
        state_name = self.current_state.transition(self.value)
        if state_name:
            self.current_state = self.states[state_name]
        
    def get_value(self):
        return self.value.value
    
if __name__ == '__main__':
    state_manage = StateManage()
    state_manage.add_state('normal', normal())
    state_manage.add_state('low', low())
    state_manage.current_state = state_manage.states['low']
    input_value = input("输入分数：")

    while True:
        if input_value.isdigit():
            state_manage.value.value = int(input_value)
            state_manage.set_state()
            print(state_manage.get_value())
        else:
            print("请输入数字！")
        input_value = input("输入分数：")

